require 'erb'
require 'common/base'

class DOT1QBase < Base

  attr_accessor :step, :transport, :base_options, :base_transports, :base_variables, :message,
    :ip_src, :ip_dst, :vlan, :vlan_pri, :vlan_cfi,:ivlan, :ivlan_pri, :ivlan_cfi, :dscp, :ping_data

  def initialize(step, filename, params = {}, transport="DOT1Q")
    super()
    @transport = transport
    @step = step

    @ip_src = params["ip_src"] or "192.168.123.1"
    @ip_dst = params["ip_dst"] or "192.168.123.2"
    @ping_data = params["ping_data"] or "12345678910"
    @vlan = params["vlan"] or "0"
    @vlan_pri = params["vlan_pri"] or "0"
    @vlan_cfi = params["vlan_cfi"] or "0"
    @ivlan = params["ivlan"] or "0"
    @ivlan_pri = params["ivlan_pri"] or "0"
    @ivlan_cfi = params["ivlan_cfi"] or "0"
    @dscp = params["dscp"] or "000000"

    @base_options = "
        $ip_src = '<%= @ip_src %>'
        $ip_dst = '<%= @ip_dst %>'
        $ping_data = '<%= @ping_data %>'
        $vlan = '<%= @vlan %>'
        $vlan_pri = '<%= @vlan_pri %>'
        $vlan_cfi = '<%= @vlan_cfi %>'
        $ivlan = '<%= @ivlan %>'
        $ivlan_pri = '<%= @ivlan_pri %>'
        $ivlan_cfi = '<%= @ivlan_cfi %>'
        $dscp = '<%= @dscp %>'"

    @base_variables = '@id = random_integer(4096)'

    @base_transports = 'DOT1Q = ethernet(type:0x8100, filter: "(ether dst src_mac or ether broadcast)")'

    if !filename.nil?
      template = get_message("DOT1Q", filename)
      erb = ERB.new(template, 0, '%<>')
      @message = erb.result(binding)
    end
  end
end
